package com.trafficsys.modules.owner.controller;

import com.trafficsys.modules.entity.Driver;
import com.trafficsys.modules.owner.service.EditMessageService;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;

@RestController
@RequestMapping("/api")
public class EditMessageController {
    @Autowired
    EditMessageService editMessageService;

    /**
     * 根据cardId修改车主的密码
     * http://localhost:8080/api/updateDriverPassword?carId=201&password=321
     *{"cardId":"201","password":"321"}
     * @param driver
     * @return
     */
    @PutMapping( value = "/updateDriverPassword" ,consumes = "application/json")
    public HashMap<String, Object> updateDriverPassword(@RequestBody Driver driver) {
        return editMessageService.updateDriverPassword(driver.getCardId(),driver.getPassword());
    }

    /**
     * 根据cardId修改车主绑定的电话
     * http://localhost:8080/api/updateTelByCardId
     * {cardId:201 ,phone:654321}
     * @param driver
     * @return
     */
    @PutMapping(value = "/updateTelByCardId" , consumes = "application/json")
    public HashMap<String, Object> updateTelByCardId(@RequestBody Driver driver) {
        return editMessageService.updateTelByCardId(driver.getCardId(),driver.getPhone());
    }
}
